﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using System.Text;

namespace Data
{
    public partial class user
    {

        public bool isValid
        {
            get {
                return (GetRuleViolations().Count()==0);
            }
        }

        public IEnumerable<RuleViolation> GetRuleViolations()
        {
            yield break;
        }



        //partial void OnValidate(ChangeAction action)
        //{
        //    if (isValid)
        //        throw new ApplicationException("Rule violation prevents saving");
        //}
    }

    public class RuleViolation
    {
        public string ErrorMessage { get; private set; }
        public string PropertyName { get; private set; }

        public RuleViolation (string errorMessage)
        {
            ErrorMessage = errorMessage;
        }

        public RuleViolation(string errorMessage, string propertyName)
        {
            ErrorMessage = errorMessage;
            PropertyName = propertyName;
        }
    }
}
